﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "ActionBase.h"

namespace gcmp
{
    class IModelView;
    class Coordinate3d;
    class IReferencePlane;
    class IGridNew;
    class ILevel;

    class GbmpSetupWorkPlaneAction : public gcmp::ActionBase
    {
    public:
        enum EnSetupWorkPlaneStatus
        {
            SWPS_STAND_BY,
            SWPS_PICK_FACE,
            SWPS_PICK_CURVE,
        };

    public:
        GbmpSetupWorkPlaneAction();
        ~GbmpSetupWorkPlaneAction();

        virtual void InitAction(gcmp::IUiView* pCurrentView) override;

    private:
        void setWorkPlaneBySelectIndex(gcmp::IUiView* pCurrentView, int idx);
        void SetWorkPlaneByModelViewIdAndCoordnate(const gcmp::ElementId& modelViewId, const gcmp::Coordinate3d& coord, int idx);

    protected:
        void SetWorkPlaneByReferencePlane(gcmp::IModelView* pCurrentView, const gcmp::IReferencePlane* refPlane);
        void GetViewCandidatesToSwitch(gcmp::IModelView* pCurrentView, const gcmp::Vector3d& planeNormal, std::vector<const gcmp::IModelView*>& arrViewName);
        gcmp::ElementId GetViewToSwitch(gcmp::IModelView* pModelView, const gcmp::Vector3d& planeNormal);
    private:
        struct AssignWorkPln
        {
            std::wstring            m_name;
            gcmp::IReferencePlane*   m_refPlane;
            const gcmp::ILevel*            m_elevation;
            const gcmp::IGridNew*              m_grid;

            AssignWorkPln()
            {
                m_refPlane = nullptr;
                m_elevation = nullptr;
                m_grid = nullptr;
            }
        };

        bool m_isUserCancelled;
        EnSetupWorkPlaneStatus      m_setWorkPlaneStatus;
        std::vector<AssignWorkPln>  m_arrAllCandidates;
    };
}


